﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChartTools
{
    /// <summary>
    /// 组合条状图
    /// </summary>
    public class MSBar3D
    {
        private List<string> Labels;
        private List<MSBar3DData> Datas;
        private string Function;
        private string ShowDivId;
        private string Title;
        public MSBar3D(List<string> pLabels, List<MSBar3DData> pDatas, string pFunction, string pShowDivId, string pTitle)
        {
            Labels = pLabels;
            Datas = pDatas;
            Function = pFunction;
            ShowDivId = pShowDivId;
            Title = pTitle;
        }
        private MSBar3D()
        {

        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<chart palette='2' caption='" + Title + "' showLabels='1' showvalues='0' decimals='0' numberPrefix='￥'>");
            sb.Append("<categories>");
            for (int i = 0; i < Labels.Count; i++)
            {
                sb.Append("<category label='" + Labels[i] + "' />");
            }
            sb.Append("</categories>");
            for (int i = 0; i < Datas.Count; i++)
            {
                sb.Append("<dataset seriesName='" + Datas[i].SeriesName + "'  showValues='0'>");
                for (int j = 0; j < Datas[i].datas.Count; j++)
                {
                    sb.Append("<set value='" + Datas[i].datas[j] + "' />");
                }
                sb.Append("</dataset>");
            }
            sb.Append("</chart>");
            string str = sb.ToString();
            sb = new StringBuilder();
            sb.AppendLine("<script type=\"text/javascript\">");
            sb.Append("            function ");
            sb.Append(Function);
            sb.AppendLine("(){");
            sb.AppendLine("                var chart = new FusionCharts(\"/Content/FusionCharts/MSBar3D.swf\", \"ChartId\", \"100%\", \"290\", \"0\", \"0\");");
            sb.AppendLine("                chart.setXMLData(\"" + str + "\");");
            sb.AppendLine("                chart.render(\"" + ShowDivId + "\");");
            sb.AppendLine("             }");
            sb.AppendLine("        </script>");
            return sb.ToString();

        }
    }
    public class MSBar3DData
    {
        public string SeriesName { get; set; }
        public List<decimal> datas { get; set; }
        public MSBar3DData()
        {
            datas = new List<decimal>();
        }
    }
}
